package com.seat.controller.User;

import com.seat.pojo.Result;
import com.seat.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@Slf4j
public class FileUploadController {

//    TODO 上传文件到阿里云，保存文件或图片地址
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        log.info("上传文件{}",file.getOriginalFilename());
   String originalFilename= file.getOriginalFilename();
   String filename=UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
    String url= AliOssUtil.UploadFile(filename,file.getInputStream());
        log.info("路径{}",url);
        return Result.success(url);
    }
}
